<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('AdvancedSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Safety')" name="1">
          <safetyPTVue :deviceType="5" :safety="safety" :reg="9" :key="timer" @getFormData="setSafety"></safetyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PowerFactor')" name="2">
          <van-form @submit="powerfactorSubmit">
            <van-field :value="LocalArr.factMode" :label="$t('ModeSelect')" readonly clickable name="picker" input-align="right" @click="showPowerFact = true" />
            <van-popup v-model="showPowerFact" round position="bottom">
              <van-picker show-toolbar :columns="powerFactors" 
                @cancel="showPowerFact = false" 
                @confirm="factModeConfirm" 
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')"
              />
            </van-popup>
            <van-field v-if="factModeCode==1||factModeCode==2" 
              v-model="LocalArr.P2Value" 
              :label="$t('PFValue')"  
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==4||safety==5||safety==7||safety==8||safety==9||safety==10||safety==11||safety==12||safety==13||safety==15||safety==16||safety==17||safety==18||safety==19||safety==20||safety==32||safety==36||safety==39)"
              v-model="LocalArr.P3Value" 
              :label="$t('UpperLimit')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo2,message: `${$t('Range')}：0.90-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==4||safety==5||safety==7||safety==8||safety==9||safety==10||safety==11||safety==12||safety==13||safety==15||safety==16||safety==17||safety==18||safety==19||safety==20||safety==32||safety==36||safety==39)"
              v-model="LocalArr.P4Value" 
              :label="$t('LowerLimit')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo2,message: `${$t('Range')}：0.90-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==4||safety==5||safety==7||safety==8||safety==9||safety==10||safety==11||safety==12||safety==13||safety==15||safety==16||safety==17||safety==18||safety==19||safety==20||safety==32||safety==36||safety==39)"
              v-model="LocalArr.P5Value" 
              :label="$t('PowerLow')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo3,message: `${$t('Range')}：0.00-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==4||safety==5||safety==7||safety==8||safety==9||safety==10||safety==11||safety==12||safety==13||safety==15||safety==16||safety==17||safety==18||safety==19||safety==20||safety==32||safety==36||safety==39)"
              v-model="LocalArr.P6Value" 
              :label="$t('PowerUp')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo3,message: `${$t('Range')}：0.00-1.00` }]" 
            />
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <pfLockInPointPTVue :setName="'PfLockInPoint'" :setUntil="'%'" :setMin="100" :setMax="110" :setValue.sync="LocalArr.PfLockInPointValue" :reg="89" v-if="isPFP&&(safety==7||safety==9||safety==32||safety==36||safety==39)"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'PfLockOutPoint'" :setUntil="'%'" :setMin="90" :setMax="100" :setValue.sync="LocalArr.PfLockOutPointValue" :reg="90" v-if="isPFP&&(safety==7||safety==9||safety==32||safety==36||safety==39)"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('SetQurangeV1')" :setUntil="'%'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.SetQurangeV1Value" :reg="122" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('SetQurangeV4')" :setUntil="'%'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.SetQurangeV4Value" :reg="123" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></pfLockInPointPTVue>
          <pfLockInPointPT2Vue :setName="$t('bQpower_set')" :setMin="bQpowerMin" :setMax="bQpowerMax" :setValue.sync="LocalArr.bQpower_setValue" :reg="124" v-if="isQSet&&safety!=4&&safety!=8&&safety!=10&&safety!=11&&safety!=12&&safety!=13&&safety!=15&&safety!=16&&safety!=17&&safety!=18&&safety!=20&&safety!=21"></pfLockInPointPT2Vue>
          <vacMaxPTVue :setName="'QuResponseV1'" :setUntil="'V'" :setMin="'195.0'" :setMax="'255.0'" :setValue.sync="LocalArr.QuVoltResponseV1Value" :reg="164" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuResponseV2'" :setUntil="'V'" :setMin="'216.0'" :setMax="'230.0'" :setValue.sync="LocalArr.QuResponseV2Value" :reg="150" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuResponseV3'" :setUntil="'V'" :setMin="'235.0'" :setMax="'255.0'" :setValue.sync="LocalArr.QuResponseV3Value" :reg="151" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuResponseV4'" :setUntil="'V'" :setMin="'244.0'" :setMax="'265.0'" :setValue.sync="LocalArr.QuResponseV4Value" :reg="152" v-if="isQu&&(safety==2||safety==5||safety==6||safety==19||safety==23)"></vacMaxPTVue>
          <div v-if="isQu&&(safety==9||safety==32||safety==39)">
            <div class="pltxt">K</div>
            <van-field
              v-model="LocalArr.qukValue"
              clickable
              readonly
              @click="showQuk = true"
            >
            <template #button>
              <van-button size="small" round @click="setQuk($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
            </van-field>
            <van-popup v-model="showQuk" round position="bottom">
              <van-picker show-toolbar :columns="QukArr" 
                @cancel="showQuk = false" 
                @confirm="QukConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
          </div>
          <pfLockInPointPTVue :setName="'3Tau'" :setUntil="'S'" :setMin="3" :setMax="180" :setValue.sync="LocalArr.ReactiveDelayTimeValue" :reg="162" v-if="isQu&&safety==5"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Grid')" name="3">
          <vacMaxPTVue :setName="$t('VacLower')" :setUntil="'V'" :setMin="'0.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinValue" :reg="5"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('VacUpper')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxValue" :reg="6"></vacMaxPTVue>
          <facMaxPTVue :setName="$t('FacLower')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinValue" :reg="7"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacUpper')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxValue" :reg="8"></facMaxPTVue>
          <vacMaxPTVue :setName="$t('Vac10MAvg')" :setUntil="'V'" :setMin="'150.0'" :setMax="'300.0'" :setValue.sync="LocalArr.Grid10MinAverageValue" :reg="11" v-if="safety!=27&&safety!=28&&safety!=29&&safety!=30&&safety!=31&&safety!=35&&safety!=37&&safety!=38"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('VacLowerSlow')" :setUntil="'V'" :setMin="'0.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinSlowProtectValue" :reg="12"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('VacUpperSlow')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxSlowProtectValue" :reg="13"></vacMaxPTVue>
          <facMaxPTVue :setName="$t('FacLowerSlow')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinSlowProtectValue" :reg="14"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacUpperSlow')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxSlowProtectValue" :reg="15"></facMaxPTVue>
          <facMaxPTVue :setName="$t('wFreqSetPoint')" :setUntil="'Hz'" :setMin="'50.20'" :setMax="'51.00'" :setValue.sync="LocalArr.wFreqSetPointValue" :reg="91" v-if="safety==5||safety==6||safety==7||safety==22||safety==23||safety==25||safety==26||safety==36"></facMaxPTVue>
          <pfLockInPointPTVue :setName="$t('wFreqDroopRate')" :setUntil="'%'" :setMin="2" :setMax="12" :setValue.sync="LocalArr.wFreqDroopRateValue" :reg="92" v-if="safety==5||safety==6||safety==7||safety==22||safety==23||safety==25||safety==26||safety==36"></pfLockInPointPTVue>
          <timeVacMinFastAdjPTVue :setName="'TuvpFast'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMinFastAdjValue" :reg="73" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TovpFast'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMaxFastAdjValue" :reg="74" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TufpFast'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMinFastAdjValue" :reg="75" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TofpFast'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMaxFastAdjValue" :reg="76" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TuvpSlow'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMinSlowAdjValue" :reg="77" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TovpSlow'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMaxSlowAdjValue" :reg="78" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TufpSlow'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMinSlowAdjValue" :reg="79" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <timeVacMinFastAdjPTVue :setName="'TofpSlow'" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMaxSlowAdjValue" :reg="80" v-if="safety==9||safety==32||safety==39"></timeVacMinFastAdjPTVue>
          <pfLockInPointPTVue :setName="'T_Start'" :setUntil="'S'" :setMin="15" :setMax="300" :setValue.sync="LocalArr.TStartValue" :reg="147" v-if="safety==2||safety==4||safety==5||safety==9||safety==19||safety==23||safety==32||safety==35||safety==37||safety==38||safety==39"></pfLockInPointPTVue>
          <facMaxPTVue :setName="$t('UFPL_StartPoint')" :setUntil="'Hz'" :setMin="'47.00'" :setMax="'49.90'" :setValue.sync="LocalArr.ufplStartPointValue" :reg="148" v-if="safety==9||safety==32||safety==39"></facMaxPTVue>
          <languagePTVue
            :setName="'OFPL_FStop'"
            :columns="toggleArr"
            :setValue="LocalArr.OFPLFStopCode"
            :reg="171"
            @getFormData="setOFPLFStop"
            v-if="safety==100"
          ></languagePTVue>
          <facMaxPTVue :setName="'OFPL_RemovePoint'" :setUntil="'Hz'" :setMin="'50.00'" :setMax="LocalArr.wFreqSetPointValue" :setValue.sync="LocalArr.OFPLRemovePointValue" :reg="172" v-if="safety==100&&isOFPLFStopData"></facMaxPTVue>
          <pfLockInPointPTVue :setName="'PfdelayTimer'" :setUntil="'S'" :setMin="0" :setMax="2" :setValue.sync="LocalArr.PfdelayTimerValue" :reg="166" v-if="safety==5"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Charger')" name="4" v-if="isLeadAcid">
          <pfLockInPointPTVue :setName="$t('MinCapacity')" :setUntil="'%'" :setMin="5" :setMax="100" :setValue.sync="LocalArr.BatteryMinEnergyValue" :reg="32"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('H/LVRTFunction')" name="5">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.HLVRTFunctionValue" :reg="160"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ExportControl')" name="6">
          <div class="pltxt">{{$t('UserValue')}} (W)</div>
          <van-form @submit="setExportLimit">
            <van-field
              v-model="LocalArr.ExportLimitValue"
              type="number" 
              show-error 
              clearable
              name="validator"
              :rules="[{ validator:ExportValidator,message:  `${$t('Range')}：0-60000` }]"
            >
            <template #button>
              <van-button size="small" round class="setbtn">{{$t('Save')}}</van-button>
            </template>
            </van-field>
          </van-form>
        </van-collapse-item>
        <van-collapse-item :title="$t('HotStandby')" name="7">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.HotStandbyValue" :reg="167"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('puFunction')" name="8" v-if="safety==2||safety==5||safety==7||safety==19||safety==23||safety==36">
          <languagePTVue
            :setName="$t('puFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.puFunctionEnableCode"
            :reg="121"
            @getFormData="setPuFunction"
          ></languagePTVue>
          <vacMaxPTVue :setName="$t('SetV1')" :setUntil="'V'" :setMin="'195.0'" :setMax="'255.0'" :setValue.sync="LocalArr.SetV1Value" :reg="165" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV2')" :setUntil="'V'" :setMin="'216.0'" :setMax="'230.0'" :setValue.sync="LocalArr.SetV2Value" :reg="118" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV3')" :setUntil="'V'" :setMin="'235.0'" :setMax="'255.0'" :setValue.sync="LocalArr.SetV3Value" :reg="119" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV4')" :setUntil="'V'" :setMin="'244.0'" :setMax="'265.0'" :setValue.sync="LocalArr.SetV4Value" :reg="120" v-if="isPu"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item title="3Tau (S)" name="9" v-if="isPu&&safety==5">
          <pfLockInPointPTVue :setMin="3" :setMax="180" :setValue.sync="LocalArr.APCMDelayTimeValue" :reg="161"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="DRM Function" name="10" v-if="safety==2||safety==19">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.DRMFunctionValue" :reg="130"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('SetWgra')" name="11" v-if="safety==2||safety==19">
          <facMaxPTVue :setName="$t('SetWgra')" :setUntil="'%'" :setMin="'5.00'" :setMax="'100.00'" :setValue.sync="LocalArr.SetWgraValue" :reg="117"></facMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PhasePowerBalance')" name="12">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.PhasePowerBalanceValue" :reg="136"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ParallelSetting')" name="13">
          <languagePTVue :columns="parallelArr" :setValue="LocalArr.ParalleSettinglValue" :reg="146"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('GridService')" name="14" v-if="safety==9||safety==32||safety==39">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.GridServiceValue" :reg="135"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('BatteryAwaken')" name="15">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.BatAwakenValue" :reg="86"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PowerLimit')" name="16">
          <pfLockInPointPTVue :setName="$t('PowerLimit')" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.ActivePowerLimitValue" :reg="17"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="17">
          <resetINVEnergyPTVue :setName="$t('ClearInverterHistory')" :reg="30"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetErrorLogs')" :reg="144"></resetINVEnergyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('NewPassword')" name="18">
          <newPasswordPTVue :setValue.sync="LocalArr.NewPasswordValue" :reg="88"></newPasswordPTVue>
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import safetyPTVue from '../../../components/Safety/BDSafetyPT'
import pfLockInPointPTVue from '../../../components/PfLockInPoint/BDPfLockInPointPT'
import vacMaxPTVue from '../../../components/VacMax/BDVacMaxPT'
import facMaxPTVue from '../../../components/FacMax/BDFacMaxPT'
import freDroopDelayTimePTVue from '../../../components/FreDroopDelayTime/BDFreDroopDelayTimePT'
import timeVacMinFastAdjPTVue from '../../../components/TimeVacMinFastAdj/BDTimeVacMinFastAdjPT'
import languagePTVue from '../../../components/Language/BDLanguagePT'
import resetINVEnergyPTVue from '../../../components/ResetINVEnergy/BDResetINVEnergyPT'
import newPasswordPTVue from '../../../components/NewPassword/BDNewPasswordPT'
import pfLockInPointPT2Vue from '../../../components/PfLockInPoint/BDPfLockInPoint2PT'

export default {
  components:{
    safetyPTVue,
    pfLockInPointPTVue,
    vacMaxPTVue,
    facMaxPTVue,
    freDroopDelayTimePTVue,
    timeVacMinFastAdjPTVue,
    languagePTVue,
    resetINVEnergyPTVue,
    newPasswordPTVue,
    pfLockInPointPT2Vue
  },
  data(){
    return {
      isLoading:false,
      timer:'',
      activeNames:[],
      safety:sessionStorage.getItem('safety'),
      showPowerFact:false,
      factorArr:[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}],
      powerFactors:[],
      factModeCode:'',
      isPFP:true,
      isQu:true,
      isQSet:true,
      bQpowerMin:'',
      bQpowerMax:'',
      qukValueCode:'',
      showQuk:false,
      QukArr:[-0.1,0.1],
      toggleArr:[this.$t('Disable'),this.$t('Enable')],
      isOFPLFStopData:false,
      isPu:false,
      parallelArr:['Free','Master'],
      isLeadAcid:false,
      LocalArr:{
        factMode:'',
        P2Value:'',
        P3Value:'',
        P4Value:'',
        P5Value:'',
        P6Value:'',
        PfLockInPointValue:'',
        PfLockOutPointValue:'',
        SetQurangeV1Value:'',
        SetQurangeV4Value:'',
        bQpower_setValue:'',
        QuVoltResponseV1Value:'',
        QuResponseV2Value:'',
        QuResponseV3Value:'',
        QuResponseV4Value:'',
        qukValue:'',
        ReactiveDelayTimeValue:'',
        VacMinValue:'',
        VacMaxValue:'',
        FacMinValue:'',
        FacMaxValue:'',
        Grid10MinAverageValue:'',
        VacMinSlowProtectValue:'',
        VacMaxSlowProtectValue:'',
        FacMinSlowProtectValue:'',
        FacMaxSlowProtectValue:'',
        wFreqSetPointValue:'',
        wFreqDroopRateValue:'',
        TimeVacMinFastAdjValue:'',
        TimeVacMaxFastAdjValue:'',
        TimeFacMinFastAdjValue:'',
        TimeFacMaxFastAdjValue:'',
        TimeVacMinSlowAdjValue:'',
        TimeVacMaxSlowAdjValue:'',
        TimeFacMinSlowAdjValue:'',
        TimeFacMaxSlowAdjValue:'',
        TStartValue:'',
        ufplStartPointValue:'',
        OFPLFStopCode:'',
        OFPLRemovePointValue:'',
        PfdelayTimerValue:'',
        HLVRTFunctionValue:'',
        ExportLimitValue:'',
        HotStandbyValue:'',
        puFunctionEnableCode:'',
        SetV1Value:'',
        SetV2Value:'',
        SetV3Value:'',
        SetV4Value:'',
        APCMDelayTimeValue:'',
        DRMFunctionValue:'',
        SetWgraValue:'',
        PhasePowerBalanceValue:'',
        ParalleSettinglValue:'',
        GridServiceValue:'',
        BatAwakenValue:'',
        ActivePowerLimitValue:'',
        NewPasswordValue:'',
        BatteryMinEnergyValue:''
      }
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/bdsetting'});
    },
    factModeConfirm(value,i){
      this.showPowerFact=false;
      this.LocalArr.factMode=value.text;
      this.factModeCode=value.code;
    },
    QukConfirm(value,i){
      this.showQuk=false;
      this.LocalArr.qukValue=value;
      this.qukValueCode=i;
    },
    fixedTwo1(val){
      return this.comm.fixedTwo(val,0.8,1);
    },
    fixedTwo2(val){
      return this.comm.fixedTwo(val,0.9,1);
    },
    fixedTwo3(val){
      return this.comm.fixedTwo(val,0,1);
    },
    ExportValidator(val){
      let vailed;
      if(val>=0&&val<=60000){
        vailed=true;
      }else{
        vailed=false;
      }
      return vailed
    },
    async getData(){
      this.comm.loadingShow();
      let datas=await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if(datas!=null||datas!=undefined){
        let dataArr = datas;
        this.safety=dataArr[4];
        sessionStorage.setItem('safety',this.safety);
        this.factModeCode=dataArr[13];
        this.LocalArr.factMode=this.factorArr[this.factModeCode].text;
        /*判断用户的选择*/
        if(dataArr[13]==3){
          this.isPFP=true;
        }else{
          this.isPFP=false;
        }
        if(dataArr[13]==4){
          this.isQu=true;
        }else{
          this.isQu=false;
        }
        if(dataArr[13]==5){
          this.isQSet=true;
        }else{
          this.isQSet=false;
        }
        this.LocalArr.P2Value=dataArr[14]/100;
        this.LocalArr.P3Value=dataArr[15]/100;
        this.LocalArr.P4Value=dataArr[16]/100;
        this.LocalArr.P5Value=dataArr[17]/100;
        this.LocalArr.P6Value=dataArr[18]/100;
        this.LocalArr.PfLockInPointValue=dataArr[96];
        this.LocalArr.PfLockOutPointValue=dataArr[97];
        this.LocalArr.SetQurangeV1Value=dataArr[129];
        this.LocalArr.SetQurangeV4Value=dataArr[130];
        this.LocalArr.bQpower_setValue=dataArr[132];
        this.bQpowerMin=this.comm.bit16(0,dataArr[134]);
        this.bQpowerMax=this.comm.bit16(0,dataArr[133]);
        this.LocalArr.QuVoltResponseV1Value=dataArr[175]/10;
        this.LocalArr.QuResponseV2Value=dataArr[163]/10;
        this.LocalArr.QuResponseV3Value=dataArr[164]/10;
        this.LocalArr.QuResponseV4Value=dataArr[165]/10;
        this.qukValueCode=dataArr[166]/10;
        this.LocalArr.qukValue=this.QukArr[this.qukValueCode];
        this.LocalArr.ReactiveDelayTimeValue=dataArr[174];
        this.LocalArr.VacMinValue=dataArr[0]/10;
        this.LocalArr.VacMaxValue=dataArr[1]/10;
        this.LocalArr.FacMinValue=dataArr[2]/100;
        this.LocalArr.FacMaxValue=dataArr[3]/100;
        this.LocalArr.Grid10MinAverageValue=dataArr[6]/10;
        this.LocalArr.VacMinSlowProtectValue=dataArr[7]/10;
        this.LocalArr.VacMaxSlowProtectValue=dataArr[8]/10;
        this.LocalArr.FacMinSlowProtectValue=dataArr[9]/100;
        this.LocalArr.FacMaxSlowProtectValue=dataArr[10]/100;
        this.LocalArr.wFreqSetPointValue=dataArr[99]/100;
        this.LocalArr.wFreqDroopRateValue=dataArr[100];
        this.LocalArr.TimeVacMinFastAdjValue=dataArr[69];
        this.LocalArr.TimeVacMaxFastAdjValue=dataArr[70];
        this.LocalArr.TimeFacMinFastAdjValue=dataArr[71];
        this.LocalArr.TimeFacMaxFastAdjValue=dataArr[72];
        this.LocalArr.TimeVacMinSlowAdjValue=dataArr[73];
        this.LocalArr.TimeVacMaxSlowAdjValue=dataArr[74];
        this.LocalArr.TimeFacMinSlowAdjValue=dataArr[75];
        this.LocalArr.TimeFacMaxSlowAdjValue=dataArr[76];
        this.LocalArr.TStartValue=dataArr[160];
        this.LocalArr.ufplStartPointValue=dataArr[161]/100;
        this.LocalArr.OFPLFStopCode=dataArr[182];
        /*判断用户的选择*/
        if(dataArr[182]==1){
          this.isOFPLFStopData=true;
        }else{
          this.isOFPLFStopData=false;
        }
        this.LocalArr.OFPLRemovePointValue=dataArr[183]/100;
        this.LocalArr.PfdelayTimerValue=dataArr[177];
        this.LocalArr.HLVRTFunctionValue=dataArr[173];
        this.LocalArr.ExportLimitValue=this.comm.mulFunction(dataArr[63],10);
        this.LocalArr.HotStandbyValue=dataArr[178];
        this.LocalArr.puFunctionEnableCode=dataArr[131];
        /*判断用户的选择*/
        if(this.LocalArr.puFunctionEnableCode==1){
          this.isPu=true;
        }else{
          this.isPu=false;
        }
        this.LocalArr.SetV1Value=dataArr[176]/10;
        this.LocalArr.SetV2Value=dataArr[126]/10;
        this.LocalArr.SetV3Value=dataArr[127]/10;
        this.LocalArr.SetV4Value=dataArr[128]/10;
        this.LocalArr.APCMDelayTimeValue=dataArr[110];
        this.LocalArr.DRMFunctionValue=dataArr[140];
        this.LocalArr.SetWgraValue=dataArr[125]/100;
        this.LocalArr.PhasePowerBalanceValue=dataArr[144];
        this.LocalArr.ParalleSettinglValue=dataArr[150];
        this.LocalArr.GridServiceValue=dataArr[143];
        this.LocalArr.BatAwakenValue=dataArr[95];
        this.LocalArr.ActivePowerLimitValue=dataArr[12];
        this.LocalArr.NewPasswordValue=this.comm.showPwd(dataArr[104]);
        //判断铅酸电池
        if(dataArr[32]==1){
          this.isLeadAcid=true;
        }else{
          this.isLeadAcid=false;
        }
        this.LocalArr.BatteryMinEnergyValue=dataArr[31];
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    //获取powerfactor列表
    getPowerFactory(){
      if(this.safety==2||this.safety==5||this.safety==9||this.safety==19||this.safety==32||this.safety==39){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}];
      }else if(this.safety==0||this.safety==1||this.safety==7||this.safety==36){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q-Set'),code:5}];
      }else if(this.safety==3||this.safety==14||this.safety==22||this.safety==24||this.safety==27||this.safety==28||this.safety==29||this.safety==30||this.safety==31||this.safety==33||this.safety==34||this.safety==35||this.safety==37||this.safety==38){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('Q-Set'),code:5}];
      }else if(this.safety==6||this.safety==23||this.safety==25||this.safety==26){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}];
      }else if(this.safety==21){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2}];
      }else{
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3}];
      }
    },
    //设置安规
    setSafety(data){
      if(data=='success'){
        this.safety=sessionStorage.getItem('safety');
        this.getPowerFactory();
      }
    },
    //设置powerfactor
    async powerfactorSubmit(){
      //处理数据
      let factorData_new={};
      factorData_new.P1Value=this.factModeCode;
      if(this.LocalArr.P2Value!=null&&this.LocalArr.P2Value!=undefined){
        factorData_new.P2Value=this.comm.mulFunction(this.LocalArr.P2Value,100);
      }
      if(this.LocalArr.P3Value!=null&&this.LocalArr.P3Value!=undefined){
        factorData_new.P3Value=this.comm.mulFunction(this.LocalArr.P3Value,100);
      }
      if(this.LocalArr.P4Value!=null&&this.LocalArr.P4Value!=undefined){
        factorData_new.P4Value=this.comm.mulFunction(this.LocalArr.P4Value,100);
      }
      if(this.LocalArr.P5Value!=null&&this.LocalArr.P5Value!=undefined){
        factorData_new.P5Value=this.comm.mulFunction(this.LocalArr.P5Value,100);
      }
      if(this.LocalArr.P6Value!=null&&this.LocalArr.P6Value!=undefined){
        factorData_new.P6Value=this.comm.mulFunction(this.LocalArr.P6Value,100);
      }
      let Datas={
        'num':3,
        'Data':[
          {'reg':24,'val':((factorData_new.P2Value)*256+Number(factorData_new.P1Value))+''},
          {'reg':25,'val':((factorData_new.P4Value)*256+Number(factorData_new.P3Value))+''},
          {'reg':26,'val':((factorData_new.P6Value)*256+Number(factorData_new.P5Value))+''}
        ]
      };
      let params={
        'optType':"setReg",
        'Data':JSON.stringify(Datas),
        'pwd':sessionStorage.getItem('bdPwd')
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(params);
      let newdata = data.substring(0,1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        /*判断用户的选择*/
        if(this.factModeCode==3){
          this.isPFP=true;
        }else{
          this.isPFP=false;
        }
        if(this.factModeCode==4){
          this.isQu=true;
        }else{
          this.isQu=false;
        }
        if(this.factModeCode==5){
          this.isQSet=true;
        }else{
          this.isQSet=false;
        }
      } else {
        this.comm.toastFail();
      }
    },
    //设置Quk
    setQuk(e){
      e.stopPropagation();
      this.comm.bdSetDataPT(1,[{'reg':153,'val':(this.comm.mulFunction(this.LocalArr.qukValue,10))+''}]);
    },
    //设置OFPLFStop
    setOFPLFStop(data){
      /*判断用户的选择*/
      if (data == 1) {
        this.isOFPLFStopData = true;
      } else {
        this.isOFPLFStopData = false;
      }
    },
    //设置ExportLimit
    setExportLimit(){
      this.comm.bdSetDataPT(1,[{'reg':66,'val':(this.LocalArr.ExportLimitValue/10)+''}]);
    },
    //设置PU Function
    setPuFunction(data){
      /*判断用户的选择*/
      if (data == 1) {
        this.isPu = true;
      } else {
        this.isPu = false;
      }
    },
    onRefresh(){
      this.isLoading = false;
      this.timer=new Date().getTime();
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
      this.getPowerFactory();
    }
  },
  mounted(){
    setTimeout(()=>{
      this.getData();
      this.getPowerFactory();
    },1000);
  }
}
</script>

<style scoped lang="less">

</style>
